<%@ page import="org.springframework.security.core.context.SecurityContextHolder" %>
<%@ page import="org.springframework.security.core.Authentication" %>
<%@ page import="com.radio.entity.hibernate.UserEntity" %>
<%@ page import="org.springframework.security.authentication.AnonymousAuthenticationToken" %>
<%@ page import="org.springframework.security.core.userdetails.User" %>
<!-- header logo: style can be found in header.less -->
<header class="header">
<a href="../../index.jsp" class="logo">
    <!-- Add the class icon to your logo image or logo icon to add the margining -->
    Radio Admin
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
</a>
<div class="navbar-right">
<ul class="nav navbar-nav">
<!-- User Account: style can be found in dropdown.less -->
    <li class="dropdown user user-menu">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            <i class="glyphicon glyphicon-user"></i>
            <%
                Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                if( !(authentication instanceof AnonymousAuthenticationToken) ){
                    //UserEntity currentLoggedInUser = (UserEntity)authentication.getPrincipal();
                    User user = (User)authentication.getPrincipal();


            %>
                <span><%= user.getUsername() + " is logged in!"%><i class="caret"></i></span>
            <%
                }else{
            %>
                <span>John Doe! <i class="caret"></i></span>
            <%
                }
            %>
        </a>
        <ul class="dropdown-menu">
            <li class="user-header bg-light-blue">
                <img src="../../img/avatar3.png" class="img-circle" alt="User Image">
                <p>


                    <small>ADMIN</small>
                </p>
            </li>
            <li class="user-footer">
                <div class="pull-left">
                    <a href="/admin/profileadmin.jsp" class="btn btn-default btn-flat">Profile</a>
                </div>
                <div class="pull-right">
                    <a href="/perform_logout" class="btn btn-default btn-flat">Sign out</a>
                </div>
            </li>
        </ul>
    </li>
</ul>
</div>
</nav>
</header>